package com.hlz.lib.effectivejava.chapter4;

import java.util.Collection;
import java.util.Set;

/**
 * 组合优于继承
 *
 * @author Hongliang Zhu
 * @create 2023-08-27 21:51
 */
public class InstrumentedHashSetWithComposition<E> extends ForwardingSet<E> {

    private int count;

    public InstrumentedHashSetWithComposition(Set<E> s) {
        super(s);
    }

    @Override
    public boolean add(E e) {
        count++;
        return super.add(e);
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        count += c.size();
        return super.addAll(c);
    }


    /**
     * @implSpec
     * @return
     */
    public int getCount() {
        return count;
    }
}


